
import '../helper/Helper.dart';
import '../helper/dioHelper2.dart';

class Recording {
   int ID;
   String SpaceId;
   String UserId;
   String Remark;
   double Lat;
   double Lng;
   String Location;
   int RType;
   String ImgId;
   String CreateTime;
   String tagName;
   String tagId;

  Recording(
      this.ID,
      this.SpaceId,
      this.UserId,
      this.Remark,
      this.Lat,
      this.Lng,
      this.Location,
      this.RType,
      this.ImgId,
      this.CreateTime,
      this.tagName,
      this.tagId);

  Recording.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        SpaceId = json["SpaceId"],
        UserId = json["UserId"],
        Remark = json["Remark"],
        Lat = json["Lat"]*1.0,
        Lng = json["Lng"]*1.0,
        Location = json["Location"],
        RType = json["RType"],
        ImgId = json["ImgId"],
        CreateTime = Helper.DateTimeFormat(json["CreateTime"]),
        tagName = json["tagName"],
        tagId = json["tagId"];

  Map<String, dynamic> toJson() => {
        'ID':ID,
        'SpaceId': SpaceId,
        'UserId': UserId,
        'Remark': Remark,
        'Lat': Lat,
        'Lng': Lng,
        'Location': Location,
        'RType': RType,
        'ImgId': ImgId,
        'CreateTime':Helper.DateTimeFormat(CreateTime),
        'tagName': tagName,
        'tagId': tagId,
      };

  static Future<bool> Add(Recording x1) async {
    var response = await DioHelper.Post("/Recording/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(Recording x1) async {
    var response = await DioHelper.Post("/Record/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(Recording x1) async {
    var st=x1.toJson();
    var response = await DioHelper.Post("/Recording/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<Recording?> Get( String where, dynamic data) async {
    var response = await DioHelper.Post("/Record/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new Recording.fromJson(response.data);
    return null;
  }

  static Future<List<Recording>> GetList2(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/Record/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <Recording>[];
    if (response.statusCode == 200) {
      if(response.data==null)
      return list1;
      for (var x in response.data) {
        list1.add(new Recording.fromJson(x));
      }
    }
    return list1;
  }




  static Future<List<Recording>> GetList(String id,int pageIndex, int pageSize) async {
    String p1=pageIndex.toString();
    String ps=pageSize.toString();

    var response = await DioHelper.Get("/Recording/GetList?SpaceId=$id&p1=$p1&ps=$ps", {  
    });

    var list1 = <Recording>[];
    if (response.statusCode == 200) {
      if(response.data==null)
      return list1;
      for (var x in response.data) {
        list1.add(new Recording.fromJson(x));
      }
    }
    return list1;
  }
}